package com.witframework.dynoengine.tool.jspc;

import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class AlaJSPSession extends Thread {
	private Hashtable tSessions = new Hashtable();
	private Hashtable tClasses = new Hashtable();
	private Hashtable tObjects = new Hashtable();
	private Hashtable tVars = new Hashtable();
	private static final long INTERVAL = 5000L;
	private static final long DURATION = 1200000L;

	public void setSessionVariable(HttpSession paramHttpSession,
			String paramString, Object[] paramArrayOfObject) {
		String str = paramHttpSession.getId();

		if (this.tSessions.get(str) == null) {
			addSession(paramHttpSession);
		}
		Hashtable localHashtable = (Hashtable) this.tVars.get(str);
		localHashtable.remove(paramString);
		localHashtable.put(paramString, paramArrayOfObject);
	}

	public void addSession(HttpSession paramHttpSession) {
		String str = paramHttpSession.getId();

		this.tSessions.put(str, paramHttpSession);
		this.tClasses.put(str, new Hashtable());
		this.tObjects.put(str, new Hashtable());
		this.tVars.put(str, new Hashtable());
	}

	public void delSession(String paramString) {
		this.tClasses.remove(paramString);
		this.tObjects.remove(paramString);
		this.tVars.remove(paramString);
		this.tSessions.remove(paramString);
	}

	public HttpSession getSession(HttpServletRequest paramHttpServletRequest,
			boolean paramBoolean) {
		HttpSession localHttpSession = paramHttpServletRequest
				.getSession(paramBoolean);

		if (localHttpSession == null)
			return null;
		if ((paramBoolean)
				&& (this.tSessions.get(localHttpSession.getId()) == null)) {
			addSession(localHttpSession);
		}
		return localHttpSession;
	}

	public Object[] getVar(HttpSession paramHttpSession, String paramString) {
		Hashtable localHashtable = (Hashtable) this.tVars.get(paramHttpSession
				.getId());

		return ((Object[]) localHashtable.get(paramString));
	}

	public Hashtable getVars(HttpSession paramHttpSession) {
		return ((Hashtable) this.tVars.get(paramHttpSession.getId()));
	}

	public Hashtable getObjects(HttpSession paramHttpSession) {
		return ((Hashtable) this.tObjects.get(paramHttpSession.getId()));
	}

	public Object getObjectInstance(HttpSession paramHttpSession,
			String paramString) {
		Hashtable localHashtable = (Hashtable) this.tObjects
				.get(paramHttpSession.getId());

		if (localHashtable == null)
			return null;
		return localHashtable.get(paramString);
	}

	public Object getClassObject(HttpSession paramHttpSession,
			String paramString) {
		Hashtable localHashtable = (Hashtable) this.tClasses
				.get(paramHttpSession.getId());

		if (localHashtable == null)
			return null;
		return localHashtable.get(paramString);
	}

	public void putClass(HttpSession paramHttpSession, String paramString,
			Object paramObject) {
		Hashtable localHashtable = (Hashtable) this.tClasses
				.get(paramHttpSession.getId());

		if (localHashtable == null)
			return;
		localHashtable.put(paramString, paramObject);
	}

	public void deleteObject(HttpSession paramHttpSession, String paramString) {
		String str = paramHttpSession.getId();

		Hashtable localHashtable = (Hashtable) this.tVars.get(str);
		if ((localHashtable != null)
				&& (localHashtable.get(paramString) != null)) {
			localHashtable.remove(paramString);
			return;
		}

		localHashtable = (Hashtable) this.tObjects.get(str);
		localHashtable.remove(paramString);
	}

	public void run() {
		System.out.println("run fired ...");
		while (this.tSessions != null) {
			System.out.println("check sessions");
			Enumeration localEnumeration = this.tSessions.keys();
			long l2 = System.currentTimeMillis();
			while (localEnumeration.hasMoreElements()) {
				String str = (String) localEnumeration.nextElement();
				System.out.println("key is: " + str);
				HttpSession localHttpSession = (HttpSession) this.tSessions
						.get(str);
				try {
					long l1 = localHttpSession.getCreationTime();
					if (l2 - l1 >= 1200000L) {
						delSession(str);
						localHttpSession.invalidate();
					}
				} catch (Exception localException) {
					delSession(str);
				}
			}
			try {
				Thread.sleep(5000L);
			} catch (InterruptedException localInterruptedException) {
			}
		}
	}
}
